#include "findcircle.h"
#include "findobject.h"

#include "backimagemanager.h"
#include <QDebug>

int findcircle::m_curfindcirclenum = 0;
findcircle::findcircle():QShape(),
    m_dwrate(1),
    m_drate(1),
    m_dpartrate(1),
    m_iSelectPointGap(3),
    m_iMethod(1),
    m_iThreshold(8),
    m_igamarate(0),
    m_dsamplerate(0.004),
    m_ifindset(1),
    m_ifilterborw(21),
    m_ifiltermin(50),
    m_ifiltermax(100000),
    m_iselectedgenum(0),//any
    m_ineedfixs(2),
    m_icomparegap(2),
    m_ishowlines(1)
{
    QString strname = QString("fline%1").arg(m_curfindcirclenum);
    setname(strname.toStdString().c_str());
    m_curfindcirclenum = m_curfindcirclenum + 1;

    int icurmodule = BackImageManager::GetCurMode();
    g_pbackimage = BackImageManager::GetBackImage(icurmodule);
    g_pbackfindobject = BackImageManager::Getbackfindobject(icurmodule);

}
findcircle::~findcircle()
{

}
void findcircle::setcomparegap(int igap)
{
    m_icomparegap = igap;
}
void findcircle::setshow(int ishow)
{
    if(ishow&0x02)
    {
        m_measurepoints.setshow(2);
    //    m_measurepoints_h.setshow(2);
    }
    if(1==ishow)
    {
        m_measurepoints.setshow(1);
    //    m_measurepoints_h.setshow(1);

    }
    QShape::setshow(ishow);

}
void findcircle::setselectedgenum(int iedgenum)
{
    m_iselectedgenum = iedgenum;
}
void findcircle::clear()
{
    m_lines.clear();
 //   m_lines_h.clear();

}
void findcircle::SetWHgap(double  dwrate,double dhrate)
{
    /*
    acentcalib.clear();
    acentcalib2.clear();
    acentcalib.circlepoints(300,350,300,452);

    alineshape.setline(300,350,300,452);
    alineshape.Show(1);
    if(1)
    {
    acentcalib.sample(0.08);
    }
    acentcalib2.pointsABadd(acentcalib);
    acentcalib.ratetopoint(300,452,-0.001);

    acentcalib2.pointsABadd(acentcalib);
    acentcalib.Show(0);
    acentcalib2.Show(6);
    */
    m_dwrate = dwrate;
    m_drate = dhrate;


}
void findcircle::setrect(int ix,int iy,int iw,int ih)
{
    QShape::settype(1);


    QShape::setrect(ix,iy,iw,iw);
}

void findcircle::setcircle(double ix, double iy, double dw )
{
    PointsShape acircle;
    m_centpoint = QPoint(ix,iy);
    acircle.circlepoints(ix,iy-dw,ix,iy);

    m_circle.clear();

    m_circle.addpoints(acircle);
    acircle.sample(m_dwrate);
    m_circleA.clear();
    m_circleA.addpoints(acircle);
    m_circleB.clear();
    m_circleB.addpoints(acircle);

    m_circleB.ratetopoint(ix,iy,m_drate);

    m_lines.clear();
     int isize = m_circleA.size();
    LineShape aline1,aline2;
    for(int i=0;i<isize;i++)
    {
        if(m_drate!=0)
        aline1.setline(m_circleA.getx(i),
                       m_circleA.gety(i),
                       m_circleB.getx(i),
                       m_circleB.gety(i));
        else
            aline1.setline(m_circleA.getx(i),
                           m_circleA.gety(i),
                           ix,
                           iy);

        m_lines.push_back(aline1);
        m_lines[i].setPercent(m_dsamplerate);
    }

}
void findcircle::sethcircle(double ix, double iy, double ix1, double iy1 )
{
    PointsShape acircle;
    m_centpoint = QPoint(ix,iy);
    acircle.halfcircle(ix,iy,ix1,iy1);

    m_circle.clear();

    m_circle.addpoints(acircle);
    acircle.sample(m_dwrate);
    m_circleA.clear();
    m_circleA.addpoints(acircle);
    m_circleB.clear();
    m_circleB.addpoints(acircle);

    m_circleB.ratetopoint(ix,iy,m_drate);

    m_lines.clear();
     int isize = m_circleA.size();
    LineShape aline1,aline2;
    for(int i=0;i<isize;i++)
    {
        if(m_drate!=0)
        aline1.setline(m_circleA.getx(i),
                       m_circleA.gety(i),
                       m_circleB.getx(i),
                       m_circleB.gety(i));
        else
            aline1.setline(m_circleA.getx(i),
                           m_circleA.gety(i),
                           ix,
                           iy);

        m_lines.push_back(aline1);
        m_lines[i].setPercent(m_dsamplerate);
    }

}
void findcircle::seticircle(double ix, double iy, double ix1, double iy1 )
{
    PointsShape acircle;
 double ix0= ix +ix1-m_centpoint.x();
 double iy0= iy +iy1-m_centpoint.y();
    m_centpoint = QPoint(ix,iy);

    acircle.arccircle(ix,iy,ix1,iy1,ix0,iy0);

    m_circle.clear();

    m_circle.addpoints(acircle);
    acircle.sample(m_dwrate);
    m_circleA.clear();
    m_circleA.addpoints(acircle);
    m_circleB.clear();
    m_circleB.addpoints(acircle);

    m_circleB.ratetopoint(ix,iy,m_drate);

    m_lines.clear();
     int isize = m_circleA.size();
    LineShape aline1,aline2;
    for(int i=0;i<isize;i++)
    {
        if(m_drate!=0)
        aline1.setline(m_circleA.getx(i),
                       m_circleA.gety(i),
                       m_circleB.getx(i),
                       m_circleB.gety(i));
        else
            aline1.setline(m_circleA.getx(i),
                           m_circleA.gety(i),
                           ix,
                           iy);

        m_lines.push_back(aline1);
        m_lines[i].setPercent(m_dsamplerate);
    }

}

void findcircle::setpart(double dpart0,double dpart1, double dsap )
{

    m_partA.clear();
    m_partB.clear();

    m_partA.addpoints(m_circle);
    m_partA.addpoints(m_circle);

    m_partA.part(dpart0,dpart1);
    m_partB.part(dpart0,dpart1);

    m_partA.sample(dsap);
    m_partB.sample(dsap);




}


void findcircle::drawpattern(QPainter &painter)
{

    m_modelpoints.setshow(8);
    m_modelpoints.drawshape(painter);
    m_measurepointsA.drawshape(painter);
    m_measurepointsA_.drawshape(painter);

}
void findcircle::drawpatternx(QPainter &painter,
                            double dmovx,double dmovy,
                            double dangle,
                            double dzoomx,double dzoomy)
{
    m_modelpoints.setshow(8);
    m_modelpoints.drawshapex(painter,dmovx,dmovy,
                            dangle,dzoomx, dzoomy);
    m_measurepointsA.drawshapex(painter,dmovx,dmovy,
                               dangle,dzoomx, dzoomy);
    m_measurepointsA_.drawshapex(painter,dmovx,dmovy,
                                dangle,dzoomx, dzoomy);

}


void findcircle::edgepattern(ImageBase &image)
{
    m_measurepointsA.clear();
    m_measurepointsA_.clear();
    m_modelpoints.clear();

    //SetWHgap(wgap(),hgap());

    setselectedgenum(0);
    setmethod(0);
    Measure(image);
    m_measurepointsA.addpoints(getresultpointsw());

    m_measurepointsA.doublepattern(m_icomparegap,12,m_modelpoints);

    setselectedgenum(0);
    setmethod(1);
    Measure(image);
    m_measurepointsA_.addpoints(getresultpointsw());

    m_measurepointsA_.doublepattern(m_icomparegap,6,m_modelpoints);

}
void findcircle::patternzeroposition()
{
    QRectF arect1 = m_modelpoints.boundingRect();
    m_modelpoints.Move(-arect1.x(),-arect1.y());
}
void findcircle::savepatternfile(const char * pchar)
{
    m_modelpoints.save(pchar);
}
void findcircle::loadpatternfile(const char * pchar)
{
    m_modelpoints.load(pchar);
}
QRectF findcircle::patternboundingrect()
{
    return m_modelpoints.boundingRect();
}

void findcircle::patterngap2gap(int inewgap)
{
    m_modelpoints.patterngap2gap(inewgap);
}
void findcircle::patternrootgrid(double itype,double drate,double ilevel)
{
    m_modelpoints.keysrootgrid(itype,drate,ilevel);
}
void findcircle::patterntranform(int igap,int itype,int isgap,int iline)
{
     m_modelpoints.patterntranform(igap,itype,isgap, iline);
}
void findcircle::patternzoom(double dx,double dy,double igap,double itype)
{
     m_modelpoints.patternzoom(dx,dy,igap,itype);
}
void findcircle::patternrotate(double dangle)
{
     m_modelpoints.Rotate(dangle);
}
void findcircle::modelzoom(double dx,double dy)
{
     m_modelpoints.Zoom(dx,dy);
}
QPainterPath &findcircle::getpatternpath()
{
    return m_modelpoints.getpath();
}
PointsShape &findcircle::getpattern()
{
     return m_modelpoints;
}
void findcircle::findpattern(void *pimage)
{
    ImageBase *pgetimage = (ImageBase*)pimage;
    edgepattern(*pgetimage);
}
void findcircle::drawshape(QPainter &painter,QPalette &pal)
{
    if(show()&0x04)
    {
        m_circle.setshow(1);
        m_circle.setPen(0,0,255);
        m_circle.drawshape(painter);

        painter.setPen(QPen(QColor(0,255,0)));
        for(int i=0;i<m_lines.size();i++)
        {
            m_lines[i].drawshape(painter);
        }
    }
    if(show()&0x02)
    {
        m_measurepoints.setPen(0,0,255);
        m_measurepoints.drawshape(painter);
    }
    if(show()&0x08)
    {
        drawpattern(painter);
    }
    if(show()&0x10)
    {

        m_partA.setshow(1);
        m_partA.setPen(0,255,0);
        m_partA.drawshape(painter);
    }

    QShape::drawshape(painter,pal);
}
void findcircle::drawshapex(QPainter &painter,QPalette &pal,
                      double dmovx,double dmovy,
                      double dangle,
                      double dzoomx,double dzoomy)
{
    if(show()&0x04)
    {

        painter.drawEllipse(m_centpoint.x()-2,m_centpoint.y()-2,4,4);
        m_circle.setshow(1);
        m_circle.setPen(0,0,255);

        m_circle.drawshapex(painter,dmovx,dmovy,
                            dangle,dzoomx, dzoomy);
        painter.setPen(QPen(QColor(0,255,0)));
        for(int i=0;i<m_lines.size();i++)
        {
            m_lines[i].drawshapex(painter ,dmovx,dmovy,
                                   dangle,dzoomx, dzoomy);
        }


       int iesize = m_edges.size();
       for(int i =0;i<iesize;i++)
       {
           if(0==m_edges[i].m_itype)
                painter.setPen(QPen(QColor(0,255,0)));
           else if(1==m_edges[i].m_itype)
               painter.setPen(QPen(QColor(255,0,0)));


           double dvaluex0 = m_edges[i].m_pointA.x();
           double dvaluey0 = m_edges[i].m_pointA.y();
           dvaluex0 = dvaluex0*dzoomx+dmovx;
           dvaluey0 = dvaluey0*dzoomy+dmovy;
           double dvaluex1 = m_edges[i].m_pointB.x();
           double dvaluey1 = m_edges[i].m_pointB.y();
           dvaluex1 = dvaluex1*dzoomx+dmovx;
           dvaluey1 = dvaluey1*dzoomy+dmovy;

           painter.drawLine(dvaluex0,dvaluey0,dvaluex1,dvaluey1);
       }
    }
    if(show()&0x02)
    {
        m_measurepoints.setPen(0,255,0);
        m_measurepoints.drawshapex(painter,dmovx,dmovy,
                                     dangle,dzoomx, dzoomy);
    }
    if(show()&0x08)
    {
        drawpatternx(painter,dmovx,dmovy,
                    dangle,dzoomx, dzoomy);
    }
 //QShape::drawshape(painter,pal);
  QShape::drawshapex(painter,pal,dmovx,dmovy,
                            dangle,dzoomx, dzoomy);
}

void findcircle::setlinesamplerate(double dsamplerate)
{
    m_dsamplerate=dsamplerate;
}
void findcircle::setlinegap(int igap)
{
    m_iSelectPointGap = igap;
}
void findcircle::setmethod(int imethod)
{
    m_iMethod = imethod;
}
void findcircle::setthre(int ithre)
{
    m_iThreshold = ithre;
}
int findcircle::thre()
{
    return m_iThreshold;
}
void findcircle::setgamarate(int igama)
{
    m_igamarate = igama;
}

void findcircle::setfindsetting(int ifindset)
{
    m_ifindset = ifindset;
}
void findcircle::setfilter(int ifilterborw,int ifiltermin,int ifiltermax)
{
    m_ifilterborw = ifilterborw;
    m_ifiltermin = ifiltermin;
    m_ifiltermax = ifiltermax;
}

void findcircle::Measure(ImageBase &image)
{


    m_measurepoints.clear();
    int iwsize = m_lines.size();
    for(int i=0;i<iwsize;i++)
    {
        m_lines[i].linecopyex(image,*g_pbackimage,0,i);
    }
    int ilineslen1 = 0;
    int ilineslen2 = 0;

    if(iwsize>0)
        ilineslen1 = m_lines[0].getlinesize();

    int iprocessw = ilineslen1>ilineslen2?ilineslen1:ilineslen2;

    g_pbackimage->SetROI(0,0,iprocessw,iwsize);

    g_pbackimage->ROIImage_7Blur_Gap_mud_thre_BW(m_iThreshold,m_igamarate,m_iSelectPointGap,m_iMethod);

    if(m_ifindset&0x01)
    {
        g_pbackfindobject->setrect(0,0,iprocessw,iwsize);
        g_pbackfindobject->setbrow(m_ifilterborw);//21 22
        g_pbackfindobject->setminmaxarea(m_ifiltermin,m_ifiltermax);
        g_pbackfindobject->Measure(*g_pbackimage);
    }


    int irecordpoint[100];
    int irecordnum =0;
    bool bcollectBegin=false;

    int icurlinenum = 0;
    int icurlineposition = 0;



    unsigned int icolor = 0;
    for(int inumy=0 ;inumy<iwsize ;inumy++)
    {
        irecordnum =0;
        icurlinenum = 0;
        bcollectBegin=false;
        for(int inumx=0;inumx<ilineslen1;inumx++)
        {
            icolor = g_pbackimage->pixel(inumx,inumy);
            if((icolor&0x0FFFF) >0)
            {
                if(irecordnum<100)
                {
                    irecordpoint[irecordnum] = inumx;
                    irecordnum++;
                }
                else
                {
                    irecordnum =0;
                    break;
                }
                bcollectBegin=true;
            }
            else
            {
                if(true==bcollectBegin
                   &&irecordnum>0
                   &&irecordnum<=70)
                {
                        icurlineposition = m_ineedfixs+irecordpoint[(irecordnum>>1)];
                        //icurlineposition = icurlineposition>ilineslen1?ilineslen1-1:icurlineposition;

                        icurlinenum++;
                        if(icurlinenum==m_iselectedgenum
                            ||m_iselectedgenum==0)//0 any
                        {
                            if(icurlineposition<(ilineslen1-m_iSelectPointGap-0)//2021 before 1
                               &&icurlineposition>m_iSelectPointGap+0)//2021 before 1
                            {
                                QPointF apoint = m_lines[inumy].getlinepoint(icurlineposition);
                                m_measurepoints.addpoint(apoint);
                                if(icurlinenum==m_iselectedgenum)
                                    break;
                            }
                        }
                }
                irecordnum =0;
                bcollectBegin=false;
            }
        }
        if(true==bcollectBegin
           &&irecordnum>0)
        {
            icurlineposition = m_ineedfixs+irecordpoint[(irecordnum>>1)];
            //icurlineposition = icurlineposition>ilineslen1?ilineslen1-1:icurlineposition;
            icurlinenum++;
            if(icurlinenum==m_iselectedgenum
            ||m_iselectedgenum==0)
            {
                 if(icurlineposition<(ilineslen1-m_iSelectPointGap-0)//2021 before 1
                    &&icurlineposition>m_iSelectPointGap+0)//2021 before 1
                    {
                        QPointF apoint = m_lines[inumy].getlinepoint(icurlineposition);
                        m_measurepoints.addpoint(apoint);
                        if(icurlinenum==m_iselectedgenum)
                            break;
                    }
            }
            irecordnum =0;
            bcollectBegin=false;
        }

    }

}
void findcircle::Search(ImageBase &image)
{
    m_measurepoints.clear();
    m_validnums.clear();
    m_disvalidnums.clear();
    m_edges.clear();
    int iwsize = m_lines.size();
    int ilineslen1 = 0;

    if(iwsize>0)
        ilineslen1 = m_lines[0].getlinesize();



    int irecordnum =0;
    bool bcollectBegin=false;

    int icurlinenum = 0;


    unsigned int icolor0 = 0;
    unsigned int icolor1 = image.pixel(m_centpoint.x(),m_centpoint.y());;

    int ipretype = -1;

    QEdge aedge1,aedge_end;
    int ilastdsnm = 0;
    int ibegdsnm = 0;
   /* if(0==m_searchdir)
    {
        for(int inumy=0 ;inumy<iwsize ;inumy++)
        {
            irecordnum =0;
            icurlinenum = 0;
            bcollectBegin=false;
            int ilineslenN = m_lines[inumy].getlinesize();
            for(int inumx=0;inumx<=ilineslenN-1;inumx++)
            {
                int ix0 = m_lines[inumy].getlinepoint(inumx).x();
                int iy0 = m_lines[inumy].getlinepoint(inumx).y();
                icolor0 = image.pixel(ix0,iy0);

                if(icolor1!=icolor0)
                {
                    m_lines[inumy].setPen(255,0,0);
                    m_disvalidnums.push_back(inumy);
                    QPointF apoint = m_lines[inumy].getlinepoint(inumx);
                    m_measurepoints.addpoint(apoint);


                    if(ipretype==0)
                    {
                         aedge1.m_itype = 0;
                    }
                    else {
                         aedge1.m_itype = 1;
                    }

                    ipretype = 1;

                 if(m_disvalidnums.size()>1)
                 {
                    aedge1.m_pointB = apoint;
                    m_edges.push_back(aedge1);
                 }
                    aedge1.m_pointA = apoint;

                    ilastdsnm = inumy;

                    int iesize = m_edges.size();
                    if(0==iesize)
                    {
                        ibegdsnm = inumy;
                         aedge_end.m_pointB = apoint;
                    }

                    break;
                }
                if(inumx==ilineslenN-1)
                {
                     m_validnums.push_back(inumy);
                     ipretype = 0;
                }
            }
        }

        if(m_measurepoints.size()>2)
        {
            if(0==ibegdsnm&&iwsize==ilastdsnm)
                aedge_end.m_itype = 1;
            else {
                aedge_end.m_itype = 0;
           }
            aedge_end.m_pointA = aedge1.m_pointA;
            m_edges.push_back(aedge_end);

        }
    }
    else
        */if(1==m_searchdir)
    {
         for(int inumy=0 ;inumy<iwsize ;inumy++)
        {
            irecordnum =0;
            icurlinenum = 0;
            bcollectBegin=false;
            int ilineslenN = m_lines[inumy].getlinesize();
            for(int inumx=ilineslenN-1;inumx>=0;inumx--)
            {
                int ix0 = m_lines[inumy].getlinepoint(inumx).x();
                int iy0 = m_lines[inumy].getlinepoint(inumx).y();
                icolor0 = image.pixel(ix0,iy0);
                if(icolor1!=icolor0)
                {
                    m_disvalidnums.push_back(inumy);
                    m_lines[inumy].setPen(255,0,0);
                    QPointF apoint = m_lines[inumy].getlinepoint(inumx);
                    m_measurepoints.addpoint(apoint);


                    if(ipretype==0)
                    {
                         aedge1.m_itype = 0;
                    }
                    else {
                         aedge1.m_itype = 1;
                    }

                    ipretype = 1;

                 if(m_disvalidnums.size()>1)
                 {
                    aedge1.m_pointB = apoint;
                    m_edges.push_back(aedge1);
                 }
                    aedge1.m_pointA = apoint;

                    ilastdsnm = inumy;

                    int iesize = m_edges.size();
                    if(0==iesize)
                    {
                        ibegdsnm = inumy;
                         aedge_end.m_pointB = apoint;
                    }


                    break;
                }
                if(inumx==0)
                {
                     m_validnums.push_back(inumy);
                     ipretype = 0;
                }
             }
         }
         if(m_measurepoints.size()>2)
         {
             if(0==ibegdsnm&&iwsize==ilastdsnm)
                 aedge_end.m_itype = 1;
             else {
                  aedge_end.m_itype = 0;
             }
             aedge_end.m_pointA = aedge1.m_pointA;
             m_edges.push_back(aedge_end);


         }
    }

}
void findcircle::findroadkey()
{
   int isize =  m_validnums.size();
   if(isize<=0)
       return;

   int iwsize = m_lines.size();
   if(iwsize<=0)
       return;
   int ibegin = 0;
   int iend = iwsize;
   int ibeginNUM = 0;
   int iendNUM =iwsize -1;
   ListVector alistx;
   if(0==m_validnums[0]
    &&(iwsize-1)==m_validnums[isize-1])
   {
       //ListVector alist;
       //ListVector blist;

       int isize =  m_validnums.size();
       for (int i = isize-1;i>0;i--)
       {
           if(m_validnums[i]-1==m_validnums[i-1])
           {
               //blist.push_back(i);
           }
           else
           {
               iendNUM =i-1;
               //blist.push_back(i);
               iend = m_validnums[i];
               break;
           }
       }
       for (int i = 0;i<isize;i++)
       {
           if(m_validnums[i]+1==m_validnums[i+1])
           {
           }
           else
           {
               ibeginNUM =i+1;
               ibegin = m_validnums[i];
              // qDebug()<<"begin:"<< i <<":"<<m_validnums[i];
               break;
           }
       }
       int ital = iend - iwsize + 1  + ibegin;
       if(ital>0)
       {
          ital=ital/2;
          m_lines[ital].setPen(0,255,255);
       }
       else
       {
          ital=(ital/2)+iwsize -1;
          m_lines[ital].setPen(0,255,255);
       }
       alistx.push_back(ital);
      // qDebug()<<QString(" mid: ") <<ital ;
   }
   isize =  m_validnums.size();
   int ibegin1 =-1;
   int iend1 = -1;
   for (int i = ibeginNUM ;i<=iendNUM ;i++)
   {
       if(-1==ibegin1)
       {
           ibegin1 = m_validnums[i];
           qDebug()<< i <<"begin :"<<m_validnums[i];
       }
       //ListVector alist;
       if(m_validnums[i]+1==m_validnums[i+1])
       {
       }
       else
       {
           qDebug()<< i <<"end :"<<m_validnums[i];

           iend1 = m_validnums[i];
             int ital = ibegin1 + iend1;
             ital=ital/2;
             m_lines[ital].setPen(0,255,255);
             alistx.push_back(ital);
             ibegin1 = -1;
       }
   }
}
PointsShape &findcircle::getresultpointsw()
{
    return m_measurepoints;
}
void findcircle::setsearchdir(int idir)
{
    m_searchdir = idir;
}
void findcircle::search(void *pimage)
{
    ImageBase *pgetimage = (ImageBase*)pimage;
    Search(*pgetimage);
}
//acentcalib.halfcircle(300,452,300,350);


void findcircle::measure(void *pimage)
{
    ImageBase *pgetimage = (ImageBase*)pimage;
    Measure(*pgetimage);
}
void findcircle::shapesetroi(void *pshape)
{
    QShape::shapesetroi(pshape);
}
void findcircle::easycluster(int igapx,int igapy,int iclusternum)
{
    PointsShape resultpoints;
    resultpoints.addpoints(getresultpointsw());
    QList<int> numlist;
    int isize = resultpoints.size();
    if(0==isize)
        return;
    for(int i=0;i<isize;i++)
    {
        numlist.push_back(1);
    }
    for(int i=0;i<isize;i++)
    {
        int ix0 = resultpoints.getx(i);
        int iy0 = resultpoints.gety(i);
        if(i+1<isize)
        for(int j=i+1;j<isize;j++)
        {
            int ix1 = resultpoints.getx(j);
            int iy1 = resultpoints.gety(j);
            if(abs(ix0-ix1)<igapx
             &&abs(iy0-iy1)<igapy)
            {
                numlist[i]++;
                numlist[j]++;
            }
        }
    }
    PointsShape amodelpointsw;
    PointsShape amodelpointsh;
    int isize1 = getresultpointsw().size();
    int isize2 = isize;
    getresultpointsw().clear();
    int inum = 0;
    for(inum=0;inum<isize1;inum++)
    {
        int ix0 = resultpoints.getx(inum);
        int iy0 = resultpoints.gety(inum);
        int inumsum = numlist[inum];
        if(inumsum>iclusternum)
        {
            getresultpointsw().addapoint(ix0,iy0);
        }
    }

}
